﻿using System;
using System.Linq;
using System.Windows.Forms;
using WTBP_v0._2.Properties;



namespace WTBP_v0._2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            txtBody.Text = Resources.Greeting;
        }

        private static void CreateCharacter(params object[] stats)
        {
            var playingCharacter = new Character();
            //Use "N" character toidentidy name
            foreach (var value in stats)
            {
                if (value.ToString()[0] == 'N')
                {
                    playingCharacter.Name = value.ToString().Substring(1);
                }
                if (value is int && value.ToString().Length == 2)
                {
                    playingCharacter.Age = Convert.ToInt32(value);
                }
                if (value is bool)
                {
                    playingCharacter.IsMale = Convert.ToBoolean(value);
                }
            }
            playingCharacter.GetId();
            Stage.AllCharacters.Add(playingCharacter);
        }

        private void FindActiveButtons()
        {
            var count = 0;
            foreach (var button in Controls.OfType<Button>())
            {
                if (button.Visible && button.Name.Substring(3,3)!= "BTN")
                {
                    Stage.AllButtons[count] = button;
                }
                count++;
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            FindActiveButtons();
            Stage.LastClickedButton = (Button)sender;
            switch (Stage.CurrentStage)
            {
                case "":
                    Stage.DateInitialize(3,12,2014,9,30);
                    txtHeader.Text = Stage.Header;
                    txtBody.Text = Resources.Intro;
                    Stage.AllButtons[0].Text = "Далее";
                    Stage.CurrentStage = "Intro";
                    CreateCharacter("NСвета",19,false);
                    break;
                case "Intro":
                    Stage.InGameDate["minute"]++;
                    txtBody.Text = Resources.NeighbourSelect;
                    Stage.AllButtons[0].Text = "*MSelectPlaceholder*";
                    button6.Visible = true;
                    button6.Text = "*FSelectPlaceholder*";
                    Stage.CurrentStage = "NeihbourSelect";
                    break;

            }
        }

        private void saveBTN_Click(object sender, EventArgs e)
        {
            var form2 = new Form2();
            form2.FormClosed += (form2_FormClosed);
            form2.ShowDialog();
            Stage.Header = txtHeader.Text;
            FindActiveButtons();
            foreach (Control control in Controls)
            {
                control.Enabled = !control.Enabled;
            }
        }

        private void form2_FormClosed(object sender, FormClosedEventArgs e)
        {
            foreach (Control control in Controls)
            {
                control.Enabled = !control.Enabled;
            }
        }
    }
}
